<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>收益计提</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript">
        var layid =11;
        layui.use(['element', 'form', 'table', 'layer', 'laydate'], function () {
            var layer = layui.layer;
            var $ = layui.$;
            var table = layui.table;
            var form = layui.form;
            var formSelects = layui.formSelects;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#statDate'
            })
            //---------------------------------------------------------------------------------------------
            table.render({
                elem: '#userTable',
                url: 'selectCashInterest',
                page: true,
                height: 'full-170'
                , minLength: 80,
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'bankName', title: '银行名称'}
                        , {field: 'cashId', title: '银行Id',hidden:true}
                        , {field: 'accountName', title: '账户名字'}
                        , {field: 'money', title: '账户余额'}
                        , {field: 'stockpileType', title: '存款类型',templet: function(item){
                            if(item.stockpileType=='2') {return '定期';
                            } else if(item.stockpileType=='1'){ return '活期';
                            }
                        }},
                        , {field: 'cardRetes', title: '年利率(%)'}
                        , {field: 'dateCashStock', title: '业务日期'}
                        , {field: 'bearingTime', title: '计息期间',templet: function(item){
                            if(item.bearingTime==2) {return 365;
                            } else if(item.bearingTime==1){ return 366;
                            }
                        }},
                        , {field: 'interest', title: '利息(元)'}
                    ]
                ]
            });
            //-----------------------------------------------------------------------------------
            table.render({
                elem: '#userTable2',
                url: 'selectBondsInterest',
                page: true,
                height: 'full-170',
                minLength:80,
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'bondName', title: '债券名称', align:'center'}
                        ,{field: 'bondId', title: '债券代码', align:'center'}
                        ,{field: 'delayDate', title: '票面利率%', align:'center'}
                        ,{field: 'quantity', title: '债券数量', align:'center'}
                        ,{field: 'interestTime', title: '债券类型',align:'center',templet: function(item){
                            if(item.interestTime=='1') {return '一年一次';
                            } else if(item.interestTime=='2'){ return '一年两次';
                            }else if(item.interestTime=='3'){ return '一年四次';
                            }
                        }},
                        ,{field: 'faceAmount', title: '票面金额',  align:'center'}
                        ,{field: 'dateStock', title: '统计日期',  align:'center'}
                        ,{field: 'bearingStart', title: '计息起始日',  align:'center'}
                        , {field: 'interest', title: '利息(元)', align: 'center'}
                    ]
                ]
            });
            //----------------------------------------------------------------------------------------------------
            table.render({
                elem: '#userTable3',
                url: 'selectTowFeesInterest',
                page: true,
                height: 'full',
                minLength:80,
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'}
                        // ,{field: 'fundName', title: '基金名称',align:'center'}
                        ,{field: 'fundId', title: '基金编号', align:'center'}
                        ,{field: 'custodianCostRate', title: '管理人费率(%)',  align:'center'}
                        ,{field: 'trusteeCostRate', title: '托管人费率(%)',  align:'center'}
                        ,{field: 'notValueCost', title: '资产净值',  align:'center'}
                        // ,{field: 'valueStatisticsDate', title: '业务日期',  align:'center'}
                        ,{field: 'trusteeInterest', title: '管理费利息(元)',  align:'center'}
                        ,{field: 'custodianInterest', title: '托管费利息(元)',  align:'center'}
                    ]
                ]
            });

            // 渲染第一个表格
            form.on('submit(searchSubmit)', function (data) {
                //console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                //console.log(data.field.statDate);
                console.log($("#statDate").val());
                // alert(  "layid=" + layid);
                if(layid==11){
                    table.reload('userTable', {
                            url:'selectCashInterest',
                            where: {
                                statDate:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }else if (layid==22){
                    table.reload('userTable2', {
                            url:'selectBondsInterest',
                            where: {
                                statDate:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }else{
                    table.reload('userTable3', {
                            url:'selectTowFeesInterest',
                            where: {
                                statDate:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

            });
            table.on('toolbar(userTable)', function(obj){
                var data = obj.data;
                if(obj.event==='tongJi'){
                    layer.msg('开始统计');
                }
            });

            form.on('submit(tongJi)', function (data) {
                //console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                //console.log(data.field.statDate);
                //alert(  "layid=" + layid);
                if(layid==11){
                    var checkStatus = table.checkStatus("userTable"); // 获得选中行所有数据
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var cashs = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        cashs.push(n);
                    });
                    // alert(cashs);
                    var cash = JSON.stringify(cashs);
                    //alert(cash);

                    layer.close();
                    //向服务端发送删除指令
                    $.post("StatisticsCash", "cash="+cash,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });


                }else if(layid==22){
                    var checkStatus = table.checkStatus("userTable2"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var Securitie = [];
                    var accountId = $("#accountId").val();
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        Securitie.push(n);
                    });
                    // alert(cashs);
                    var Securities = JSON.stringify(Securitie);
                    //alert(Securities);
                    //alert(accountId);
                    // layer.close();
                    //向服务端发送删除指令
                    $.post("StatisticalBond", {
                        Securities: Securities,
                        accountId: accountId
                    }, function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }else{
                    var checkStatus = table.checkStatus("userTable3"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var TwoFee = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        TwoFee.push(n);
                    });
                    // alert(cashs);
                    var TwoFees = JSON.stringify(TwoFee);
                    // alert(TwoFees);
                    var statDates=$("#statDate").val();
                    var statDate = JSON.stringify(statDates);
                    // alert("返回的日期"+statDate)
                    // layer.close();
                    //向服务端发送删除指令
                    $.post("StatisticalTowFees",
                        {
                            TwoFees:TwoFees,
                            statDate:statDate
                        }
                        ,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }

            });

        });

    </script>
</head>
<body>
<div style="margin-top: 20px;margin-left: 10px">
    <form id="searchDate" class="layui-form layui-col-space5">
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">业务日期</label>

            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" autocomplete="off" placeholder="请输入统计日期" name="statDate" id="statDate">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" lay-submit="" lay-filter="searchSubmit" ><i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" type="button" lay-submit="" lay-event="tongJi" lay-filter="tongJi"><i class="layui-icon layui-icon-table"></i>统计
            </button>
        </div>
    </form>
</div>
<div class="layuimini-main">
    <div class="layui-tab layui-tab-brief" lay-filter="test1" >
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">现金利息</li>
            <li lay-id="22">债券利息</li>
            <li lay-id="33">两费</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <!--表格-->
                <table id="userTable" lay-filter="userTable"></table>
            </div>
            <div class="layui-tab-item">
                <table id="userTable2" lay-filter="userTable2"></table>
            </div>
            <div class="layui-tab-item">
                <table id="userTable3" lay-filter="userTable3"></table>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use('element', function(){
        var element = layui.element;

        // // 获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
        // var layid = location.hash.replace(/^#test1=/, '');
        // element.tabChange('test1', layid); //假设当前地址为：http://a.com#test1=222，那么选项卡会自动切换到“发送消息”这一项
        // alert(layid);
        //

        //监听Tab切换，以改变地址hash值
        element.on('tab(test1)', function(){
            location.hash = 'test1='+ this.getAttribute('lay-id');

        });
        element.on('tab(test1)', function () {
            layid = this.getAttribute('lay-id');
            // alert(layid);

        });

    });
</script>
</body>
</html>